using System.Collections.Generic;
using SimpleJSON;
using UnityEngine;

namespace Gj
{
    public class ChangeManageHelper : NodeHelper
    {
        public GameObject item;
        public List<ChangeItemHelper> tmp;
        protected override BindDataType bindDataType => BindDataType.List;

        protected override void BindData(JSONArray arr)
        {
            for (int i = 0; i < arr.Count; i++)
            {
                ChangeItemHelper helper;
                if (tmp.Count == 0)
                {
                    helper = ModelTools.Create(item, gameObject).GetComponent<ChangeItemHelper>();
                }
                else
                {
                    helper = tmp[0];
                    tmp.RemoveAt(0);
                }
                helper.SetParent(this);
                helper.SetData(arr[i].AsObject);
                helper.Show();
            }
            arr.Clear();
            Emit(UIEvent.End);
        }

        public void Recovery(ChangeItemHelper helper)
        {
            tmp.Add(helper);
        }
    }
}